﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        private Storyboard myboard;

        public Window1()
        {
            InitializeComponent();

            StackPanel myPanel = new StackPanel();
            myPanel.Margin = new Thickness(10);

            Rectangle myRect = new Rectangle();
            myRect.Name = "myRect";
            this.RegisterName(myRect.Name, myRect);
            myRect.Width = 100;
            myRect.Height = 100;
            myRect.Fill = Brushes.Blue;
            myRect.Loaded += new RoutedEventHandler(myRect_Loaded);

            myPanel.Children.Add(myRect);
            this.Content = myPanel;

            DoubleAnimation animation = new DoubleAnimation();
            animation.From = 1.0;
            animation.To = 0.0;
            animation.Duration = new Duration(TimeSpan.FromSeconds(500));
            animation.AutoReverse = true;
            animation.RepeatBehavior = RepeatBehavior.Forever;

            myboard = new Storyboard();
            myboard.Children.Add(animation);

            Storyboard.SetTargetName(animation, myRect.Name);
            Storyboard.SetTargetProperty(animation, new PropertyPath(Rectangle.OpacityProperty));

        }

        void myRect_Loaded(object sender, RoutedEventArgs e)
        {
            myboard.SpeedRatio = 100;
            myboard.Begin(this);
        }

        private void Rectangle_Loaded(object sender, RoutedEventArgs e)
        {

        }
    }
}
